package com.hirsi.module.menu.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.hirsi.module.menu.service.MenuService;
import com.hirsi.module.menu.vo.EditMenuVo;
import com.hirsi.module.menu.vo.result.ApiTreeSelectorResult;
import com.hirsi.module.menu.vo.result.MenuTreeResult;
import com.hirsi.module.menu.vo.result.PermissionResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "菜单管理")
@ApiSupport(order = 5)
@RestController
@RequestMapping("v1/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @ApiOperation("获取页面菜单操作权限")
    @ApiOperationSupport(order = 1)
    @GetMapping("permission")
    public PermissionResult permission() {
        return menuService.permission();
    }

    @ApiOperation("获取菜单操作树形列表")
    @ApiOperationSupport(order = 2)
    @GetMapping("tree")
    public List<MenuTreeResult> tree() {
        return menuService.tree();
    }

    @ApiOperation("获取接口选择数据(开发环境)")
    @ApiOperationSupport(order = 5)
    @GetMapping("dev/api_tree_selectors")
    public List<ApiTreeSelectorResult> devApiTreeSelectors() {
        return menuService.devApiTreeSelectors();
    }

    @ApiOperation("编辑回显菜单(开发环境)")
    @ApiOperationSupport(order = 6)
    @GetMapping("dev/edit")
    public EditMenuVo devEdit(@ApiParam(value = "菜单id", required = true) @RequestParam Integer id) {
        return menuService.devEdit(id);
    }

    @ApiOperation("保存菜单(开发环境)")
    @ApiOperationSupport(order = 7)
    @PostMapping("dev/save")
    public void devSave(@RequestBody EditMenuVo vo) {
        menuService.devSave(vo);
    }
}
